'use strict';
const requireEx =require('yi-require');
const request=require('yi-request');

module.exports = {
    open:false,
    description:'新增商品',
    handler(){
        request(options,function(err,body){

            xmlreader.read(body.toString("utf-8"), function (errors, response) {
                if (null !== errors) {
                    console.log(errors)
                    return;
                }
                console.log('长度===', response.xml.prepay_id.text(), response.xml.return_code.text());

                if(response.xml.return_code.text()==='SUCCESS'){
                    var prepay_id = response.xml.prepay_id.text();
                    //将预支付订单和其他信息一起签名后返回给前端
                    let finalsign = wxpay.paysignjsapimini(appid,mchid,prepay_id,nonce_str,timestamp,mchkey);
                    let data ={'appId':appid,'partnerId':mchid,'prepayId':prepay_id,'nonceStr':nonce_str,'timeStamp':timestamp,'package':'Sign=WXPay','sign':finalsign};

                    callback(null,data);
                }else{
                    callback('发起支付失败！',body);
                }
            });

        });
    }
};
